package test.bean;

import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class ClientJMS{
	public static InitialContext getInitialContext() throws NamingException {
		Properties properties = new Properties();
		properties.put(Context.INITIAL_CONTEXT_FACTORY,
				"weblogic.jndi.WLInitialContextFactory");
		properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
		properties.put(Context.SECURITY_PRINCIPAL, "weblogic");
		properties.put(Context.SECURITY_CREDENTIALS, "blackberry9800");
		return new InitialContext(properties);
	}
	public static void main(String... strings) {
		QueueConnection queueConnection=null;
		try {
			InitialContext context=getInitialContext();
			QueueConnectionFactory queueConnectionFactory=(QueueConnectionFactory) context.lookup("jms.ConnectionFactory-0");
			Queue queueJMS=(Queue) context.lookup("jms.Queue-0");
			
			queueConnection=queueConnectionFactory.createQueueConnection();
			QueueSession queueSession=queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
			QueueSender queueSender=queueSession.createSender(queueJMS);
			
			for(int mID=0;mID<9;mID++){
				MapMessage mapMessage=queueSession.createMapMessage();
				mapMessage.setInt("JMS Message ID	", mID);
				queueSender.send(mapMessage);
			}
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			if(queueConnection!=null && queueConnection!=null)
				try {
					queueConnection.close();
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}


	}

}
